#coding=utf-8
import glob
import jieba
import re
import json
from common.attr_v3 import AttrV3
from database.db_handler import MysqlHander

'''
属性枚举值入库
'''

class AttrV3Data:
    def __init__(self, file):
        self.db = MysqlHander("config.ini")
        self.table = ""
        self.file = file
        self.v3 = AttrV3()

    def write_db(self, d):
        data = d.split("|")
        if len(data) == 0:
            return
        relation = int(data[2])
        self.table = self.v3.get_table_name(relation)
        if relation != 3999:
            self.v3.add_attr_data(self.db, self.table, data[0], data[3], data[4], data[5], data[6])
        else:
            self.v3.add_attr_data_temp(self.db, data[0], data[2], data[3], data[4], data[5], data[6])

    
    def record_attr(self):
        with open(self.file, 'r', encoding='utf-8') as f:
            self.data = f.readlines()
        for b in self.data:
            self.write_db(b)

if __name__ == '__main__':
    code = AttrV3Data('./out/shangjiaosuo_jianguan_data.txt')
    code.record_attr()